/**
 * Lop nay dam nhiem viec ma hoa
 * @author: Huan
 */
package control;

import java.math.BigInteger;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

public class MD5Service {
	
	/**
	 * nhan vao 1 string va tra ve ma md5 cua string do
	 * @param str: xau muon ma hoa
	 * @return: chuoi hash md5 cua str
	 */
	public static String md5From(String str) {
		try {
			MessageDigest md = MessageDigest.getInstance("MD5");
			byte[] messageDigest = md.digest(str.getBytes());
			BigInteger number = new BigInteger(1, messageDigest);
			String hashtext = number.toString(16);
			//
			while (hashtext.length() < 32) {
				hashtext = "0" + hashtext;
			}

			return hashtext;
		} catch (NoSuchAlgorithmException e) {
			throw new RuntimeException(e);
		}

	}
}